Is there a way to "combine" the SelectOneManu and autoComplete feature?
When the form is loaded I'd like that input field to display the current value of the bean property, plus ability to select a new value with autoComplete.
Primefaces already provides this already in the autocomplete component. Just look on the demo site. By adding the dropdown="true" on the autocomplete menu, you enable support for a dropdown. Concretely, follow the following steps to get your results
Set dropdown="true" on your autocomplete menu. Then set the completeMethod to correspond to a method on your backing bean that returns a list of the items you want to show up in the dropdown menu.
To preset the value on the autocomplete component, simply initialise the value in the backing bean to whatever you want. Take the following as an example. If you have
<p:autoComplete id="dd" dropdown="true" value="#{yourBackingBean.myVariable}" completeMethod="#{yourBackingBean.loadOptions}" />
In your backing bean, you initialise the myVariable type during it's declaration
String myVariable = "Desired Value";
If you're going to be populating the dropdown list with a list of complex/POJO types (and as a result, bind the value attribute to a complex type in the backing bean), you'll need to use the converter based autocomplete component implementation
Related
I’m using ScalaTest to write Selenium acceptance tests for a Play web app. I have a checkbox I want to check, using the checkbox function:
checkbox("cbx1").select()
As far as I can tell, it takes the name attribute of the <input> element to identify which checkbox I’m referring to. However, this checkbox is one of eight, and its name attribute is in the form fieldname[7]. I don’t have access to its index in my test, so I can’t generate the right name attribute value.
Is there a way to use the checkbox function with a CSS selector to identify which checkbox should be selected? I’ve tried passing a CSS selector straight to the function:
checkbox("""[name=^"fieldname"][value="TheCheckboxValue"]""").select()
But unsurprisingly, I get an error:
WebElement '[name^="fieldname"][value="TheCheckboxValue"]' not found.
Aha — this seems to work:
checkbox(cssSelector("""[name=^"fieldname"][value="TheCheckboxValue"]""")).select()
I'm new to Magnolia, and I'm making my own module.
I have a dialog box when adding a component and I want to change next fields below dynamically using a select field.
Example:
Select field with {"type 1", "type 2", ...}
IF "type 1" is selected
->show a text field below
ELSE
->show a basicUpload field below
Thanks in advance.
I believe same was already discussed here and few other places if you look over questions tagged "magnolia".
Long story short, fields are atomic, independent entities. They do not know about each other. So the only way to create such dynamic connection is over "parent" form. You need to extend form presenter and field factory (if you want select that would be SelectFieldFactory) and in there, when field is created, attach value changed or similar listener to it so when value is changed in the field, you can inform presenter to make some other field visible or hide it.
IIRC you can see example of that done in External Forms module (if you have access to enterprise code). Not sure if any of the community modules show the same.
I want to set value of autocomplete field using xf:setvalue. I know that firstly I have to set value of field and then set label (#label). I try to do that in following way:
<xf:setvalue ref="xxf:instance('fr-form-instance')//*[name() = $autocomplete-name]" value="'myValue'"/>
<xf:setvalue ref="xxf:instance('fr-form-instance')//*[name() = $autocomplete-name]/#label" value="'labelValue'"/>
After that in form builder I see, that in main instance it looks properly:
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
<form>
<section-5>
<control-10 label="labelValue">myValue</control-10>
</section-5>
</form>
</xf:instance>
but unfortunately in my autocomplete field there is no change. I can notice the change only if I go to 'edit source' button in form builder, and without any change, I click 'apply'. Then autocomplete is automatically refreshed and I see my label: 'labelValue'. What should I do, to refresh autocomplete field after setvalue ??
regards
You need to do this by setting the label of the autocomplete, not its value, which is done by dispatching the fr-set-label event to the autocomplete control. Then, internally, the autocomplete will do something very similar to what it does if the user had entered that label, in particular calling the service to retrieve the corresponding value.
I'm new to JBPM and am trying to wrap my head around a new project, and recently noticed that while trying to define some user task forms I couldn't find a form option for a drop-down list
At this point my knowledge of the technology is pretty small, and this seems like a strange limitation at first glance, which should have an easy work-around, but I'm having difficulty finding a quick and dirty solution.
Is this something I'd have to code in Eclipse, or something else?
The answer that #cego provides is correct for "hard-coded" values, if you want to load dynamic values (from a database for example) you can use the Select Box field type and configure it to use a SelectValuesProvider that calculates the combo values.
To create a SelectValuesProvider you should create a java project with a mvn dependency to:
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-form-modeler-api</artifactId>
</dependency>
Once you did that you can create your class that implements org.jbpm.formModeler.core.config.SelectValuesProvider. This interface provides two methods:
String getIdentifier(): should return a unique String that identifies this provider. This String will be shown on the Select Box configuration popup.
Map getSelectOptions(Field field, String value, FormRenderContext renderContext, Locale locale): This method have to return a Map containting the key, text that are going to be load on the Select box. The received parameters are:
Field field: the configuration of the field that is going to be evaluated.
String Value: the current value of the field
FormRenderContext renderContext: a class that contains all the information about the form that is rendered at that moment.
Locale locale: the locale in which is being rendered the form.
Once you've created this provider, you must compile your project and put the jar on the server classpath and restart it. After doing that you'll be able to create a form (or edit an existing one), add a Select Box field and choose your provider on the "Data provider" combo box.
Hope it helps, if you have any doubt please ask and I'll try to create an example.
Regards,
Pere
Ok, for old versions you can do it turning a textbox to a combobox using a RangeProvider. This is a very similar solution to the previous one.
First you should create java project with a mvn dependency to:
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-form-modeler-api</artifactId>
</dependency>
After that you have to create your RangeProvider class that implements org.jbpm.formModeler.api.model.RangeProvider and implement it's methods. As the SelectValuesProvider on the previous example this interface provides two methods:
- String getType(): A unique String to identify the provider
- Map getRangesMap(String namespace): This method have to return a Map containting the key, text that are going to be load on the combo box. It only receives a String parameter, it is an identifier that allows you to get all the information about the form that is being rendered.
Also you have to create a META-INF/beans.xml file to allow to lookup your provider via CDI (I missed this step on the previous example, sorry).
As the previous example, once you've created the provider you must compile your project and put the jar on the server classpath and restart it.
When the server is started you have to create a new form (or open an existing one), add a TextBox field, edit it's properties and write the string returned by your RangeProvider's getType method on the "Range value" property.
Save the field properties and if everything is fine the field would be rendered as a combobox showing the values returned by your provider.
To create a select element(drop-down list) look for "Setting a Range Formula" in this part of the documentation: http://docs.jboss.org/jbpm/v6.1/userguide/chap-formmodeler.html#sect-formmodeler-FormulasExpression
OK, let's start with the Html.Textbox. It is supposed to contain text read from a file. The file read is based on what the user picks from a dropdown list.
The first time it is fine. The user picks a value from the dropdown list. The controller uses that value to read some text from a file, and returns that text to the view via the view model. Everything is fine.
THen the user picks another value from the dropdown list. The controller reads a new value from a file and returns it via the view model. Debugging to the LINE BEFORE THE HTML.TEXTBOX is set in the view shows that the model contains the correct value. However, the textbox itself still shows the PREVIOUS value when the page displays!
If I switch from Html.Textbox to a plain input, type="text" html control, everything works fine. That's not so hard, but the same thing happens with my dropdown list -- I can't set the selected value in code. It always reverts to whatever was chosen last. Rendering a "select" tag with a dynamically-generated option list is a pain. I would love to be able to use Html.Dropdown.
What am I missing here?? This is such a simple thing in webforms!
When you post a form, the values that are posted are put into ModelState. When the HtmlHelper renders an html iunput element, e.g. Html.TextBoxFor(x => x.FirstName), it'll search various locations to get the value for the textbox... ModelState is before ViewData.Model in the list of locations. So there for, the previously posted value will appear in your textbox.
To fix this you could clear the ModelState value or update the ModelState value. BUT I would kinda view that as a hacky way of getting around the problem.
The real issue has more to do with the flow of the posts and requests. I would personally look into that and maybe implement the PRG (Post Redirect Get) pattern.
HTHs,
Charles
Following on from what Charles/Charlino said:
Model binding updates the ModelState object, which contains validation and model binding errors that are collected during model binding.
Inside an action method, model binding has occurred already to update the model, and generated the ModelState object. If you now update the value on the model inside the action, you must also manually update the model state (since the helpers use it to generate their HTML). Below is an example:
model.CaptchaIsValid = CaptchaService.ValidateAndExpireCaptcha(model.CaptchaAttempt);
if (!model.CaptchaIsValid)
{
ModelState.AddModelError("CaptchaAttempt", "Incorrect - please try again");
}
// I'll clear the value on each attempt, to force them to re-enter a CAPTCHA.
model.CaptchaAttempt = string.Empty;
// Since I updated the model, I must create a new ValueProvider result...
ValueProviderResult clearedValue = new ValueProviderResult(
model.CaptchaAttempt,
model.CaptchaAttempt,
CultureInfo.CurrentCulture);
// ... and update the ModelState's value.
ModelState.SetModelValue("CaptchaAttempt", clearedValue);
The biggest issue I see here is that you are trying to do a postback within MVC. That model is really not supported, and is actually way more trouble than it is worth (as it seems you are finding out). I would recommend using Ajax to update the contents of the dropdown dynamically.