Triggering event on input/select value change with Spring web flow - spring

I wanna trigger flow change when user change the value in select box:
<select>
<options>
<option>1</option>
<option>2</option>
</options>
</select>
After reading this docs: https://docs.spring.io/spring-webflow/docs/current/reference/html/spring-mvc.html#spring-mvc-resuming-on-event
I did not find the answer.
Please can any one help? Any advice appreciated.
The change I wanna achieve is to set button to be activated, when value has been chosen from select box.

there are 2 ways to do this:
First, using strictly javascript (all in the UI), by using onchange and/or onclick on your select element to find the button and activate/deactivate it
Second, using Webflow:
submit the form on onchange
re-render the view with the proper changes
Assuming you want to go with webflow here, you can use this:
JSP
<form id="myFormId" action="${flowExecutionUrl}" method="post">
<select id="mySelectId" onchange="Spring.remoting.submitForm('mySelectId', 'myFormId', {fragments:'body', _eventId: 'myChangeEvent'}); return false;">
...
</select>
</form>
Flow
<view-state id="myViewStateId">
<transition on="myChangeEvent" validate="false" bind="true">
<!-- change some property to enable your button -->
</transition>
</view-state>
This will re-render the view and the property/attribute you are using to enable/disable your button will be updated.
It is important to use validate="false" otherwise validation error(s) could prevent your transition from succeeding

Related

Struts 2 XML form validation breaks when new element that does not need validation is added

I am facing an issue that is really hard to debug. I have a JSP page that has some form elements on it that submit to a Struts2 action. I also have a XML form validation file to perform some validation on the submitted fields. The file has the naming convention 'actionName-validation.xml'
This works fine, but when I add a drop down box, outside of the form, the validation now fails. Instead it redirects to a blank page and my breakpoint in my action class is not hit.
Is there a way to turn on some kind of debugging or logging for the validation? Why would adding a tag outside of a form cause this to happen?
Here is the code on the JSP page:
<s:select id="dataSource" name="selectedDataSource" theme="simple" listValue="top"
headerKey="" headerValue="Choose Data" list="dataSources" size="1" />
<div id="forms">
<s:form method="post" action="MyAction" theme="simple">
<p>
<label class="input" for="name"
<span style="color:red;">*</span>
<span>Name</span><br>
<s:textfield theme="simple" name="name" maxlength="11" size="11" />
<br>
<s:fielderror theme="plain"><s:param value="'name'" /</s:fielderror></label>
</p>
<s:submit value="Create New" theme="simple" cssStyle="display: block; clear: left;"/>
</s:form>
</div>
If I remove the <s:select> tag, it works.
Any help would be greatly appreciated it.
EDIT2: I found the problem. I needed a get method for the list that is used to populate the select drop down inside the action that the form submits to.
I had one for the action that initially is called for the page, but when the validation fails and it re-loads that page from the form action class, it tries to re-populate the select drop down and needs a getter there. I feel silly for not finding that sooner. Would be nice if there were some type of logging or messaging of these types of issues.
thanks.
The error you are encountering is not a validation error (handled by the Validation Interceptor), but an error occurred when setting the parameters (raised by the Parameters Interceptor) and for which the Conversion Error Interceptor added a fieldError, which you are not seeing because
your INPUT result lands on a blank page and
you are using theme="simple" on the textfield, which forces you to add <s:fielderror fieldName="dataSource" /> to show it (or <s:fielderror /> to show them all).
Read how the INPUT result works, set your page as the INPUT page, print the errors, then you will discover the problem, that is most likely related to the fact that you've not specified a listKey attribute in your select, that is sending the description instead of the code of the datasource to selectedDataSource, which is probably an Integer.
I found the problem. I needed a get method for the list that is used to populate the select drop down inside the action that the form submits to.
I had one for the action that initially is called for the page, but when the validation fails and it re-loads that page from the form action class, it tries to re-populate the select drop down and needs a getter there. I feel silly for not finding that sooner. Would be nice if there were some type of logging or messaging of these types of issues.

joomla 2.5 controller actions

please tell me where the actions in a joomla 2.5 controller written. in joomla 1.5 i remember we use to write the actions like add, edit, remove, cancel etc in the only controller. but i am puzzled in joomla 2.5 because i find three controller even for helloworld component. and i also don't find the functions for actions defined in the controller. i saw only display function in the main controller.
then i also wanna know how each JToolbar button is mapped to an action in the controller.
First of all those methods are not shows in the controller that means its in library section.
For your requirement you can create new or same methods in any of the controller If you use same methods like save(), delete() cancel() etc its will override the Joomla's default functions.
In your toolbar section you can have mention the function name as well.
JToolBarHelper::title('Yor custom component', 'head vmicon48'); //set title
JToolBarHelper::apply('saveConfig'); //when the apply button click its will call the saveConfig function the controller.
JToolBarHelper::cancel();
For some toolbar button argument order may different you can find here.
Also if you have more than one controller from your form you can mention the controller like as follows.
<input type="hidden" name="option" value="com_helloworld" />
<input type="hidden" name="view" value="yourview" />
<input type="hidden" name="task" value="my_controller_fun" />
<input type="hidden" value="your_controller_file_name" name="controller">
Hope you will get some idea !

value in render is not taking its form on an Ajax refresh

I have the below code
<a4j:jsFunction name="selectGroupForManagingCtns"
action="#{ctnGrpMgmtController.loadCTNsForAGroup}"
render="ctnListPanel,ctnTable">
<a4j:param name="name" assignTo="#{ctnGrpMgmtController.groupId}" /> </a4j:jsFunction>
</a4j:jsFunction>
After loadCTNsForAGroup is executed in the backing bean, the required components are not rendered after an ajax refresh. Have to make an F5 to view them.
Please help.
You need to use reRender attribute instead of render
http://docs.jboss.org/richfaces/latest_3_3_X/en/tlddoc/a4j/jsFunction.html

Navigating from one page to Another page in spring webflow

can anyone give a simple example for spring webflow to navigate from one page to another page using a button
you need to be more a little more specific. but if you just want to navigate from one page to another, in terms of Webflow you can do this in the same flow:
these 2 pages will be 2 view-state and by clicking on a button you want to trigger an event that will transition you to from one to the other.
<view-state id="viewState1" view="viewPage1.html">
<transition on="nextPage" to="viewState2"/>
</view-state>
<view-state id="viewState2" view="viewPage2.html">
<transition on="previousPage" to="viewState1"/>
</view-state>
in your web page, you just need a submit button like this:
page 1:
<input type="submit" name="_eventId_nextPage" value="Next Page"/>
page 2:
<input type="submit" name="_eventId_previousPage" value="Previous Page"/>
I strongly advice you to read the documentation and some tutorials as there are many ways to accomplish this

How to get a DropDownList select action to trigger submit button in MVC 4?

I have a DropDownList in an MVC 4 web application that is used as a filter. When a new value is selected from the drop down, the user then has to click the submit button. Is there a way to get the DropDownList to perform the same submit action when a new item is selected from the drop down so I can eliminate the submit button altogether? No custom methods have been written for the submit button, I am just using the generic one that is in MVC.
Update: Code is as follows:
#Html.DropDownList("userName",Model.Users) <input type="submit" value="Search" />
<select name="dropdown" id="dropdown" onchange="this.form.submit()">
p.s. first link in Google search results
Edit
#Html.DropDownList("userName",Model.Users new {onchange="this.form.submit()"})

Resources