JTable JQuery and one to many relationships - jquery-jtable

Hello I need to show with jtable an entity. i have in my db impl/dto one 'one to many relationship', this boils down to have a set of objects related with an entity. More specifically:
public class UserEntityDTOImpl{
#JsonProperty("UserId")
private Long userId;
#JsonProperty("UserName")
private String userName;
....
#JsonProperty("UserAddress")
private Set<AddressEntityDTOImpl> userAddress = new HashSet<AddressEntityDTOImpl>(0);
...
}
public class AddressEntityDTOImpl {
#JsonProperty("AddressId")
private Long address_id;
#JsonProperty("Country")
private String country;
#JsonProperty("Address")
private String detailAddress;
#JsonProperty("PostCode")
private String postCode;
....
}
and i am talking about UserAddress.
What i want is to use jtable and have enabled CRUD operations on the user including address list of each user (see user's address list, delete address list entries, add new address list entries and update existing ones).
I am stuck exaclty on the address list and need help on jtable as i am tottaly new to jtable/jquery/javascript.
i was thinking jtable supports something like this but could not find anything. The way i was thinking of it was to have something like one jtable inside another in terms that each user in my main jtable has one inner jtable which would have the address list.
Is this possible? If yes a short example how i can do this would be perfect.
If no, anyone had same issue to cope with and any proposals how to handle it?
If nothing of the above is applicable, one further question is as follows to use as work around, can i add somehow an extra button per row (next to delete/update buttons of jtable), which when pressed will direct me to another page?
i.e. {edit address button}-->/users/edit/address?userId={user.getId}
then if this is possible i could have a second jquery at another page to cope with specific user's address list.

Does this look similar to your use case?
http://jtable.org/Demo/MasterChild

Related

Acumatica. Get ItemClass Attributes on Sales Order dialog box

I’m trying to get the Attributes per ItemClassId to place them on a grid in the look up dialog box (Sales Order Entry).
enter image description here
I’m using the CSAttributeGroupList method:
public PXFilter<SOSiteStatusFilter> ItemSearchClass;
{
[PXViewName("Attributes")]
CSAttributeGroupList<INItemClass, SOSiteStatusFilter> Attributes;
public PXFilter<SOSiteStatusFilter> ItemSearchClass;
[PXViewName("Attributes")]
CSAttributeGroupList<INItemClass, SOSiteStatusFilter> Attributes;
}
I can't find the proper way to bring the attributes from each ItemClassID.
I have tryed:
public CSAttributeGroupList<INItemClass, SOSiteStatusFilter> Attributes;
But it doesn't work either.
I would first put SyncPosition=True on the grid to the right, to ensure that the current inventory item is selected. From there, you would want to use the code that is found in InventoryItemMaintBase:
public CRAttributeList<InventoryItem> Answers;
This would pull the current inventory item's attributes, and should automatically link to the items answers. You may need to mess with getting the grid on the right to refresh after the row is selected for the inventory item, if it does not do it automatically.

How to add action menu on specific position

As per title. A new action menu is automatically added to the bottom of the list. Is there a way to force them to appear on specific index or just before/after a specific action ?
Thanks in advance
In Automation Steps screen, in Actions tab you can find the button REORDER ACTIONS, this may help you.
PXGraph class has an action collections declared as:
public readonly PXActionCollection Actions;
It is a class deriving from .Net framework OrderedDictionary.
You can access it directly in your class deriving from PXGraph:
this.Actions
In the context of a graph extension deriving from PXGraphExtension it is available though Base member:
Base.Actions
Look at the public methods exposed by Actions, I think Move might be able to swap the Actions order in the menu. Here is some usage examples:
public PXAction<APInvoice> release;
public PXAction<APInvoice> prebook;
// Resolving name with static check
Base.Actions.Move(nameof(release), nameof(prebook));
// Using action display name with runtime check
Base.Actions.Move("Release", "Pre-book");

Access a component of a custom control

I have a custom Control which I'll call ccViewTemplate with this code in it:
<xp:repeat id="repeatData" rows="30"
value="#{viewEntry}" var="veData"
first="#{javascript:return (sessionScope.ssFirst != null)?sessionScope.ssFirst:0;}">
<xp:panel id="panelSelect">
<xp:callback facetName="viewBodyFacet" id="callback1"></xp:callback>
</xp:panel><!-- panelSelect -->
</xp:repeat>
the database view (viewEntry) is also defined in ccViewTemplate and defined based on several custom properties. ccViewTemplate is then added to another custom Control called ccFinalView. Where the custom properties are entered, and the content of the display is entered into viewBodyFacet. I have access to veData and a everything works great to this point. In the viewBodyFacet I have a link that does a redirect to open the document which also works fine. However, in the link I want to get the repeatData Property First and store it so that it returns to the correct page of the repeat. I use this code:
sessionScope.put('ssFirst',getComponent("repeatData").first);
However, the code can not find the getComponent("repeatData") because it is inside ccViewTemplate and not accessible. Is there a way to get the component repeatData from the ccViewTemplate while in ccFinalView which contains ccViewTemplate.
I have done getComponent("ccViewTemplate") and I have the handle to the custom Control, but
getComponent("ccViewTemplate").getComponent("RepeatData").first fails. So is there a way to pull a value from a component 'inside' a custom control from 'outside' the custome control?
looked a little further and found this:
var rtn = getComponent("ccViewTemplate").getPropertyMap().getProperty("repeatData");
It does not generate an error but returns nothing, if I add
var rtn = getComponent("ccViewTemplate").getPropertyMap().getProperty("repeatData").first;
I get an error getComponent() is null
Hope this makes sense.
From what I understand, this is a perfect job for a java bean. The bean can even keep a default value.
public class Controller{
public String value;
public Controller(){
value = "default_value";
}
public String getValue(){return value;}
public void setValue(String value){this.value=value}
}
In this fashion, the value will be available as soon as the object is created. pressing the button then sets the value with javascript,
ControllerBean.setValue("thisValue");
and you can read the value
ControllerBean.getValue();
This question shows how to configure the bean: How to set up a managed bean to work with Notes document
By setting this to, say the viewScope, you can then access the value anywhere you need regardless of whether or not it is in a custom control or main page. I highly recommend this approach. It just means possibly rethinking your custom control structure.
EDIT
Extra ideas include having an enum that maintains the views,
public enum Views{
VIEW_1("viewAlias", "urlParam")
private String vwAlias;
private String urlParam;
private Views(String alias, String param){
vwAlias = alias;
urlParam = param;
}
// public getters
}
And then in your controller you can get the view string:
1. By seeing if a view param is included in the URL
2. If a cookie value is set
3. Take the hard coded default
Clicking the change view action then sets the cookie value and changes the view parameter and redirects.
This is all extra ideas, but it is how I build my view controllers. I will be doing a tutorial on that soon.

Save all rows in an h:dataTable

I have a Facelets page with a h:dataTable. In each row of the h:dataTable, i am displaying some enabled and disabled services of a user.Here is the model object
public class ServiceList {
private long userId;
private long serviceGroupId;
private String serviceGroupName;
private long serviceId;
private String serviceName;
private String serviceUrl;
private String serviceState;
public UserServiceList() {
}
//getters and setters....
}
These are the details i am displaying in a single row of a dataTable.
serviceState in the above model object is either 'Y' or 'N'.
my problem is the application user should be able to update the servicestate of all rows of a dataTable at once and update them in the backend database.
1)what additional JSF component do i need to use inside dataTable to achive this? I am thinking of adding one more column with h:selectOneradio
2)How do i get which rows are selected and what status they have set?
I am kind of newbee to JSF.Please help.
Update:At present what i am having is two buttons namely 'Disable Service' and 'Enable Service' in the footer section of the table.
Onclick of Disable Service i am navigating to another page where i show the application user the list of enabled services to disable
And vice-versa for Enabled service button click.
So, let's say you in your Managed Bean you have a list of services you would like the user to edit:
List<Service> serviceList;
You take this List to be displayed in the data table.
<h:dataTable value="#{yourManagedBean.serviceList}" ... >
Then you can implement a commandButton that has either an action or an actionListener which points to a certain method of your managed bean, like this:
<h:commandButton action="#{yourManagedBean.saveAllAction}" ... >
And the corresponding method to save 'em all is quite straight-forward. You iterate over the managed bean field serviceList and persist every single entry (however you persist them, like calling the EntityManager when using Hibernate or any DAO class in between, you name it.)
Concerning the service status: I'd preferably use a selectBooleanCheckbox for toggling the status, since it's probably a boolean value.
Edit after comment 1:
You have the serviceStatus in your Service class. Currently it's a string, but I suppose it should be boolean to toggle active/inactive. If this property is displayed by the selectBooleanCheckbox it is automatically changed in your corresponding Java class. So calling getServiceStatus() returns true or false, depending on what is selected in the frontend. If you persist the whole Service object then, you don't have to do anything because any modifications made in the frontend HTML elements are automatically projected to the Java object behind it.

Maintaining state between pages in seam

I have a xhtml page with Search criteria and search results. Clicking on search button will dynamically update the results on the same page. I have a controller for search/results xhtml in Page Scope.
There is an edit button in every record in the search results. Clicking on the edit button will open a new page(new controller in Page scope). Once I edit and save I want to come back to the search criteria page with search resutls.
I can store the search criteria in session and requery and display the results. I looked at conversation and I am not sure if I can use it in this scenario?
Any ideas other than dumping the data in session for this scenario?
Pass the search criteria to the edit view as well (but don't display them or something) and then let the edit view pass it back to the search view once editing is finished.
If you want to persist data between two pages, you have many ways:
1) String parameters
2) Session data
3) Long running Conversation
4) Serialize your data elsewhere (DB or other).
Since you are talking about "saving" I may think you are saving your data in a database. If you have persisted your data in the second page in some way you can just query for them.
Otherwise you can use session and conversation, the second has a "smaller" and defined scope. You can decide when to create one and to create destroy. Simply put a in the first page pages.xml and create a bean with conversation scope.
The session scope will keep your data in your session scoped component until you close your browser.
Hope this helps.
I would go with the session scoped bean. If you use a search bean you can go anywhere in your application and maintain your search state, also it lends itself to saving searches in the database (so users can save searches between sessions).
#Scope(ScopeType.SESSION)
#Name("someRandomSearch")
public class SomeRandomSearch {
private SearchObj1 userSelection1;
private List<SearchObj1> searchCriteriaList1;
private SearchObj2 userSelection2;
private List<SearchObj2> searchCriteriaList2;
private String randomUserInput;
// getters/setters, some helper classes, cascade dropdown stuff, etc.....
// clear search criteria
public void reset(){
this.userSelection1 = null;
this.userSelection2 = null;
this.randomUserInput = null;
}
}
Just make sure to implement equals method in your model classes - maybe that's obvious, but when I first started using Seam I missed this little tidbit and it took forever to figure out why we couldn't hold onto dropdown selections in our search pages.
If when you say "open a new page", you mean navigate to another page in the same browser window/tab, then a Conversation is the ideal method for storing the search state.
Depending on your detailed use case, you might prefer to setup nested conversations (when you click on the edit).
You might also want to setup a pageflow to manage that particular navigation logic.
See the official documentation.

Resources