Open three tabs of accordion panel - jsf-2

I have an accordion panel with 5 tabs Namely Department Name, student Name, serial number, age and comments.In each tab, I have prime faces text area to enter. After entering all details I am saving it. Now I will try to edit this information. While editing information I want the accordion panel implementation as below,
When I click on edit how to make p:inputTextarea enable so that it can be edited. Currently tab is high lighted not the p:inputTextarea.
when any information is edited, respective tab should be highlighted after saving. For example age and comments are edited, I have to highlight two tabs after saving, so that user can understand that age and comments has been edited. setting Active index opens only one tab. setting mutiple to true opens all the tabs. How to implement this?

use the binding attribute of the accordian panel. when you save data, decide which tab need to be highlighted. In backing bean set the active tab accordingly.
Example:
In your view:
<p:accordionPanel autoHeight="false" binding="#{mybackingbean.panel}" ....other attributes you need... />
in backing bean:
#ManagedBean(name="mybackingbean")
public class MyBackingBean
{
private AccordionPanel panel;
//Setter and getter for panel
public String saveAction()
{
if(somecondition)
{
panel.setActiveIndex(1);
}
else
{
panel.setActiveIndex(0);
}
return "";
}
}

Related

How to make a TextAreaItem's value clickable and hyperlink in SmartGwt?

I'm having a dynamic form which is having a TextAreaItem and the value for text Area is populated from database.
I want to make the value of Text Area Clickable and hyperlink ,Could you please help which event handlers and attributes I shuld set to get the desired output?
I think that you will want to use a LinkItem rather than TextAreaItem. A LinkItem can be used to show a clickable hyperlink. You can set the target of the LinkItem to "javascript" and add a form item ClickHandler to perform an action on click.
See the Forms - Various Controls sample.
I have tried using LinkItem too but if you make the link editable (link.setCanEdit(true)) then you loose the ability of opening the link by clicking on it. Probably because the click handler is now used to edit the field. You might need to add some extra mechanism to open the link, like adding a button or something.
Here it's an example:
private void urlForm() {
url = new LinkItem();
url.setShowTitle(false);
url.setCanEdit(true);
url.setValue("yourURL");
ButtonItem button = new ButtonItem("Go");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.open(url.getLinkTitle(), "_blank", "");
}
});
urlForm = new DynamicForm();
urlForm.setNumCols(4);
urlForm.setFields(url, button);
}
Another alternative could be adding a new view to edit the URL value, and leave the LinkItem as non editable, so the link will open when clicking on it.

Dynamic columns in Primefaces datatable

I want to create a dynamic datatable using Primefaces that reflects user's choice. The user can choose one of the two radio buttons and then the datatable will be shown to the user.
The only difference between two radio buttons is that choosing the second one the datatable will contain an additional column.
Is it possible to create such datatable, using Primefaces and JSF?
Easiest solution would be to set rendered attribute of column depending on radio button selected.
...
<h:column rendered="#{myBean.radioValue}">
...
radio button 1 -> myBean.radioValue=false
radio button 2 -> myBean.radioValue=true

Child field event handling issue in custom HorizontalFieldManager

I am trying to create a customized list field where, I have more then 2 clickable buttons in each row. For that i have customized the HorizontalFieldManager and created own manager to align the field elements. Now UI is perfectly fine.
But, I am struggling to handle the events work for both.
Step-1 I have used fieldChangedListener for buttons added in row. It is working fine
public void fieldChanged(Field field, int context) {}
step-2 have used navigation click to handle event on the parent manager.
protected boolean navigationClick(int status, int time) {
Field field = getFieldWithFocus();
Dialog.alert("shops field clicked");
return super.navigationClick(status, time);
}
Now, even the navigationClick event works. But as the button is the child field added to VFM. When i click on the button both the VFM and button event comes together.
How could i restrict only to the button while it is clicked on the ButtonField.
If I understood your question correctly, you want the navigationClick() to be called only for the child field (clickable button) without being called for the manager. Sorry to disappoint you, but you can't.The navigation click event will always be called first for the manager and only than the manager will propagate the event to the child field. The same hold for keys events, touch events, focus events and etc...
Describe what you are trying to achieve, add a code snippet and I am sure we will find a solution.

ASP MVC ViewData from one view to another (Html.Encode())

I have a page with a bunch of labels and checkboxes on it. On this page, the labels need to be easily customizable after the project is deployed.
So I made all of the labels in this style:
Html.Encode(ViewData["lblText"])
And I added a button on the page called "Edit Button Labels" that will only be seen by admins.
When that button is clicked, I would like to load another view that simply contains a table of two columns. One column needs to contain the current labels and the other should have text boxes for the user to enter new labels.
Then, once any changes have been made, I need to permanently change the "lblText" for each label on the original page.
I have tried passing viewdata and tempdata to the "Edit Button Labels" view using both return view() and return RedirectToAction() with no success. Am I missing something minor or is there a better way to do this?
Don't use ViewData is the first thing I'd say. Return a model to your view which contains the labels. Create a composite model if required.
Then, to edit your labels, go to a view that takes the same model, allows you to enter the new text and saves the results to the xml, db, text file, whatever.
So you might have a model like this;
public class Labels
{
public List<string> text{ get; set; }
}
So in your db layer, wherever that is, fill the object with the label text items.
On your EDIT view you should then do the following imho;
<% Html.PartialView("EditLabels", Model); %>
Then you have a partial view called EditLabels and it would have something like the following psuedo;
foreach(string item in Model)
{
<% Html.PartialView("labelEdit", item); %>
}
Then finally you have a partial view that takes a single item and allows you to edit it called labelEdit.
This, in my opinion, is the correct way to do it in MVC as to breaks the entire view into chunks of functionality and seperates the concerns nicely.
Obviously you still need an ActionResult to take a post and affect the changes.

ModelState.IsValid for invisible controls

I am working on MVC with C#.
I have 2 radio buttons. On selecting first radio button, a textbox will be shown which allows to enter date values.
<%= Html.TextBox("ReceivedDate")%>
on selecting the second radio button, the textbox gets hidden.
For the first time, when i select first radio button and entered date and clicked Next to navigate to next page and came back to this page again and clicked second radio button and clicked Next to continue and again i came back to this page and without changing any option click continue, its not allowing to navigate and shows an error.
A value is required.
Which means the ModelState validating the hidden controls also.
Please suggest how to control it
Instead of hiding it remove the element from the DOM and reinsert it if the first item is selected again. Another way would be to change the name of the input control to something else (a key not present in your model data) when the first item is not selected.
Validating hidden input types is a good thing, i often use them to synchronize data from complex controls (like a treeview with checkboxes). An input type with a hidden css style doesn't make it not submit with the form it belongs too.

Resources