Search Results

Search found 4 results on 1 pages for 'jamiebarrow'.

Page 1/1 | 1 

  • JavaFX - question regarding binding button's disabled state

    - by jamiebarrow
    I'm trying to create a dummy application that maintains a list of tasks. For now, all I'm trying to do is add to the list. I enter a task name in a text box, click on the add task button, and expect the list to be updated with the new item and the task name input to be cleared. I only want to be able to add tasks if the task name is not empty. The below code is my implementation, but I have a question regarding the binding. I'm binding the textbox's text variable to a string in my view model, and the button's disable variable to a boolean in my view model. I have a trigger to update the disabled state when the task name changes. When the binding of the task name happens the boolean is updated accordingly, but the button still appears disabled. But then when I mouse over the button, it becomes enabled. I believe this is due to JavaFX 1.3's binding being lazy - only updates the bound variable when it is read. Also, when I've added the task, I clear the task name in the model, but the textbox's text doesn't change - even though I'm using bind with inverse. Is there a way to make the textbox's text and the button's disabled state update automatically via the binding as I was expecting? Thanks, James AddTaskViewModel.fx: package jamiebarrow; import java.lang.System; public class AddTaskViewModel { function logChange(prop:String,oldValue,newValue):Void { println("{System.currentTimeMillis()} : {prop} [{oldValue}] to [{newValue}] "); } public var newTaskName: String on replace old { logChange("newTaskName",old,newTaskName); isAddTaskDisabled = (newTaskName == null or newTaskName.trim().length() == 0); }; public var isAddTaskDisabled: Boolean on replace old { logChange("isAddTaskDisabled",old,isAddTaskDisabled); }; public var taskItems = [] on replace old { logChange("taskItems",old,taskItems); }; public function addTask() { insert newTaskName into taskItems; newTaskName = ""; } } Main.fx: package jamiebarrow; import javafx.scene.control.Button; import javafx.scene.control.TextBox; import javafx.scene.control.ListView; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.scene.layout.HBox; def viewModel = AddTaskViewModel{}; var txtName: TextBox = TextBox { text: bind viewModel.newTaskName with inverse onKeyTyped: onKeyTyped }; function onKeyTyped(event): Void { txtName.commit(); // ensures model is updated cmdAddTask.disable = viewModel.isAddTaskDisabled;// the binding only occurs lazily, so this is needed } var cmdAddTask = Button { text: "Add" disable: bind viewModel.isAddTaskDisabled with inverse action: onAddTask }; function onAddTask(): Void { viewModel.addTask(); } var lstTasks = ListView { items: bind viewModel.taskItems with inverse }; Stage { scene: Scene { content: [ VBox { content: [ HBox { content: [ txtName, cmdAddTask ] }, lstTasks ] } ] } }

    Read the article

  • jsf immediate="true" question regarding binding to session bean

    - by jamiebarrow
    Hi, I have a listing page that goes to an add page. The add page has a name textbox whose value is bound to a session scoped bean. The listing page has an add button that goes via an action method to the add page. This action method clears the object that the name textbox is bound to. I also have a cancel button on the add page, which is bound to an action method that again clears the value that the name textbox is bound to. If nothing is set to immediate, this all works fine. However, if I set the cancel button to immediate, if I enter values in the name field, and then click cancel, the action method is fired and clears the object in the backing bean and goes to the listing page. If I then click add, the action method clears the object again (ignore if it's best method or not) and then goes to the add page. I would now expect the add page's name textbox to be empty, but it's not?! Surely, since the add button is not immediate, the values should be re-bound and empty? Below is the relevant XHTML for the add button on the listing page <h:commandButton id="addButton" value="Add" action="#{myBean.gotoAdd}"/> Below is the relevant XHTML for the input box on the add page (myBean is session scoped), followed by that of the cancel button on the add page.: <h:inputText id="newName" value="#{myBean.newObject.name}" binding="#{myBean.newNameInput}" styleClass="name" /> <h:commandButton id="cancelButton" value="Cancel" immediate="true" action="#{myBean.cancelAdd}" onclick="return confirm('You sure?');"/>

    Read the article

  • Modifying JSF Component Tree in PhaseListener

    - by jamiebarrow
    Hi all, I'm having an issue. I've implemented a PhaseListener, which is meant to add a style class to any UIInput components in the tree that have messages attached to them, and removes the style class if it doesn't have any messages attached to them. The PhaseListener runs in the RENDER_RESPONSE phase, and does it's work in both the beforePhase and afterPhase methods while debugging. While debugging, I found that beforePhase doesn't have access to the full component tree, but afterPhase does. Any changes done in afterPhase aren't rendered though. How do I go about this? I want this to be completely server side. Thanks, James

    Read the article

  • JSF 2 - clearing component attributes on page load?

    - by jamiebarrow
    Hi, The real question: Is there a way to clear certain attributes for all components on an initial page load? Background info: In my application, I have a JSF 2.0 frontend layer that speaks to a service layer (the service layer is made up of Spring beans that get injected to the managed beans). The service layer does its own validation, and I do the same validation in the frontend layer using my own validator classes to try and avoid code duplication somehow. These validator classes aren't JSF validators, they're just POJOs. I'm only doing validation on an action, so in the action method, I perform validation, and only if it's valid do I call through to the service layer. When I do my validation, I set the styleClass and title on the UIComponents using reflection (so if the UIComponent has the setStyleClass(:String) or setTitle(:String) methods, then I use them). This works nicely, and on a validation error I see a nicely styled text box with a popup containing the error message if I hover over it. However, since the component is bound to a Session Scoped Managed Bean, it seems that these attributes stick. So if I navigate away and come back to the same page, the styleClass and title are still in the error state. Is there a way to clear the styleClass and title attributes on each initial page load? Thanks, James P.S. I'm using the action method to validate because of some issues I had before with JSF 1.2 and it's validation methods, but can't remember why... so that's why I'm using the action method to validate.

    Read the article

1