i have an issue with a DropDownChoice (the DDC) component. The situation is as following: I want to create a simple registry page for a contest. So i need a team with participants. I have created a form (which is a composition of different panels/forms) on which you can enter the name, age and 'position in the game'. Then you press the 'add participant' button and the participant should appear in the DropDownChoice.
I am new to Apache Wicket and actually i am glad i get the form to show on the screen and to see that the participants are actually added to the DDC. But here comes the issue: All of the participants in the DDC are 'turned into' the last one added. In other words: suppose i create the participant Jeff. Jeff gets added to the DDC, no problem. Then i create Mike. When i add Mike to the DDC and look at the available participants, Jeff seems to have been turned into Mike. So at this point, i do have 2 participants in my team, but the first one,Jeff, i suddenly Mike as well. And it is not only the property which is displayed that has changed. It is the complete content of the Participant object that turns into Mike.
Now if i would like to add Janine, Jeff and Mike would both turn into Janine and i would have 3 'Janine participants' in my DDC. I ll add the code of the 'TeamForm', which i believe is the most relevant. If needed, i can put more code on.
package com.tvh.tournamentregistry.form;
import com.tvh.tournamentregistry.model.Participant;
import com.tvh.tournamentregistry.model.Team;
import com.tvh.tournamentregistry.panel.ParticipantPanel;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
public class TeamForm extends Form {
public TeamForm(String id){
super(id);
final Team team = new Team();
CompoundPropertyModel<Team> teamModel = new CompoundPropertyModel<Team>(team);
setModel(teamModel);
add(new TextField("name"));
Model<Participant> participantModel = new Model<Participant>();
ChoiceRenderer<Participant> teamViewRenderer = new ChoiceRenderer<Participant>("firstname");
final DropDownChoice<Participant> teamView = new DropDownChoice<Participant>("players",participantModel, team.getPlayers(), teamViewRenderer){
#Override
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
};
add(teamView);
final ParticipantPanel participantPanel = new ParticipantPanel("participantpanel");
add(participantPanel);
Button addParticipant = new Button("addparticipant"){
#Override
public void onSubmit() {
Participant participant = (Participant) participantPanel.getModel().getObject();
team.getPlayers().add(participant);
teamView.setChoices(team.getPlayers());
teamView.render();
participantPanel.clear();
}
};
addParticipant.setDefaultFormProcessing(false);
add(addParticipant);
}
#Override
protected void onSubmit() {
super.onSubmit(); //To change body of generated methods, choose Tools | Templates.
}
}
I have debugged the little application and what i saw was quite disturbing. i put a breakpoint on
Participant participant = (Participant) participantPanel.getModel().getObject();
after adding 2 participants, so i could have a look at the
team.getPlayers()
method which returns a list of participants. The model that gets returned by the paricipantspanel (which is a custom method, passing the model from the form in that panel) is correct. It returns the participant that i have entered in my form. But when i look in the team list, even before my debugger get to that line, i can see that all the other participants have 'changed' already. And i am not touching the list, only adding new participants.
Any thoughs anybody? Thanks! If this was absolutely not clear, please ask!
Each time you add a new participant, the ParticipantPanel must have its model "re-initialized" otherwise its model object references the same object all the time.
In detail:
Participant a.
On first render, your panel uses this participant so on add, it adds it to you list.
After that, while re-rendering, the model object of the panel is still point to participant a. So changes affect the old object. That's why your dropdown has your single participant repeated.
Try the following:
Instead of using getter, use PropertyModel
new DropDownChoice<Participant>("players",participantModel, team.getPlayers(), teamViewRenderer)
change to
new DropDownChoice<Participant>("players",participantModel, new PropertyModel(team, "players"), teamViewRenderer)
Specify idExpression in ChoiceRenderer
new ChoiceRenderer<Participant>("firstname");
change to
new ChoiceRenderer<Participant>("firstname", "id");
Related
I have two pick-list in Car details entity. I'm setting the Model (cir_model) Picklist value with from the input parameter (that is CrmNumber) of Custom Workflow activity and it's working as expected, and the second pick-list Marque (cir_marque) will be set logically using the Model pick-list.
Logic should be if Model is set to 'Ac Ace' then Marque should be set to 'Ac'. Take value 'Ac' using Split() from the string 'Ac Ace'.
Normally in C# this can be done easily but in CRM 4.0 how this can be achieve (How I'll set 'Ac' to Marque)
public static DependencyProperty modelProperty = DependencyProperty.Register("model",
typeof(int), typeof(CreateCardetails));
[CrmInput("Model")]
public int model
{
get
{
return (int)base.GetValue(modelProperty);
}
set
{
base.SetValue(modelProperty, value);
}
}
public static DependencyProperty ContactProperty =
DependencyProperty.Register("Contact", typeof(Lookup), typeof(CreateCardetails));
[CrmInput("Contact ID")]
[CrmReferenceTarget("contact")]
public Lookup Contact
{
get
{
return (Lookup)base.GetValue(ContactProperty);
}
set
{
base.SetValue(ContactProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext
executionContext)
{
//Create an car details record which will be linked to the contact record
DynamicEntity cardetails = new DynamicEntity("cir_cardetails");
cardetails["cir_carsdetailsid"] = Contact;
//Setting the picklist value of Model
Picklist modelPickList = new Picklist();
modelPickList.Value = model.Value;
cardetails.Properties.Add(new PicklistProperty("cir_model",modelPickList));
/*
Here the logic should be done for setting Marque (cir_model) value
Picklist marquePickList = new Picklist();
marquePickList.Value = ???
cardetails.Properties.Add(new PicklistProperty("cir_marque",marquePickList));
*/
//Creating the car details record
Guid carkey = crmService.Create(cardetails);
}
How we can set the Marque value logically, I have left the code blank for this like below
/*
Here the logic should be done for setting Marque (cir_marque) value
Picklist marquePickList = new Picklist();
marquePickList.Value = ???
cardetails.Properties.Add(new PicklistProperty("cir_marque",marquePickList));
*/
Please arrange to help me out on this, all suggestions are welcome.
There is no language CRM 4.0, in CRM 4.0 you code in c#. The only thing that change is the way you work with new types.
In Workflow you don't work with controls, you work with entities and the related attributes. So you "just" need to get the attribute cir_model, do a subtring and find the available options in Marque and set the corrected value. Check this sample from SDK.
You can use JavaScript or C# (Plug-In, Workflow) to accomplish this. There are some considerations to think of when choosing which approach to use.
If you want the user to be able to see the result in real time (when they select) then you can use JavaScript.
If you don't care for the user to see the result, or there is data coming in from an outside source (not the user form), then think about using a plugin.
I don't think you should have to use a WF to do this, plugins are just as easy to write and will happen instantaneously instead of waiting for the async process to complete.
I'm using glazedlists for auto-completion but i want to ask something in this point. I have an arraylist for friendlist. People can be added to friendlist or can be removed from friendlist by clicking add or remove button. Data of friendlist is written to friend.txt and is read from friend.txt ,by using Gson and Json.
When user add a person to the list or remove a person from the list the selected person is removed from or added to friend.txt.
...
Object[] elements = new Object[holdSizeValue];
for( int i = 0 ; i < holdSizeValue ; i++ ){
elements[i] = sendFriendNameFromList(i);
}
searchBox = new JComboBox<Object>();
final EventList<Object> eventList = GlazedLists.eventList(Arrays.asList(elements));
SwingUtilities.invokeAndWait(new Runnable() {
#Override
public void run() {
AutoCompleteSupport.install(searchBox, eventList);
}
});
...
As you might understand from the code, i used glazedlist for search operation.I want to update elements[]. How can i update ? When i call the method ,which includes the code above , from controller of add or remove button i am getting an exception which is about invokeAndWait.
The major advantage of the EventList is that once it's initialised you simply add objects to it and everything that is observing that data, e.g., the ComboBox will magically update thanks to all the plumbing GlazedLists provides.
So, move the EventList to be an instance variable:
private EventList<Object> eventList = new BasicList<Object>();
Perform the AutoCompleteSupport once, after the searchBox has been created and set up.
Then, when you need to add items call eventList.addAll(...). Don't reinstantiate that list, nor reinstanstiate the searchBox each time you want to do an update. Add/remove with the event list and the rest will follow automatically.
I need to get the component associated to a Activity at the event system.
I try to get the component ID using:
public void OnActivityInstanceFinishPost(ActivityInstance activityInstance, string finishMessage, string nextActivity, string dynamicAssignee)
{
if (activityInstance.ProcessInstance.ProcessDefinition.Title.Equals("Component Process IESE"))
{
if (activityInstance.ActivityDefinition.Title.Equals("Create or Edit Component"))
{
WFE workflow = tdse.GetWFE();
try
{
Component comp = (Component)activityInstance.ProcessInstance.Item;
XMLReadFilter filter = new XMLReadFilter();
String processHistoryId = activityInstance.ProcessInstance.ID.Replace("131076", "131080");
ProcessHistory hist = (ProcessHistory)tdse.GetObject(activityInstance.ProcessInstance.ID, EnumOpenMode.OpenModeView, Constants.URINULL, filter);
}
catch (Exception e)
{ }
}
}
}
we try different options:
Component comp = (Component)activityInstance.ProcessInstance.Item;
But this solution returns a null.
Then I found in internet the next solution:
XMLReadFilter filter = new XMLReadFilter();
String processHistoryId = activityInstance.ProcessInstance.ID.Replace("131076", "131080");
ProcessHistory hist = (ProcessHistory)tdse.GetObject(activityInstance.ProcessInstance.ID, EnumOpenMode.OpenModeView, Constants.URINULL, filter);
Component comp = hist.Item as Component;
But the ProcessHistory object is null.
How can I determine the component associated to the activityInstance?
Thank you.
After reviewing the functionality needed by Guskermitt, I've shown him a neater way to do what he needs to do. In short, EventSystem is not needed in this case.
His goal is to send an email after a component has been approved, the approach will be the following:
Add to workflow a new automatic activity.
Create a new .NET assembly, in this case a C# class to do what he needs to do.
Register the assembly in the GAC.
Add logic in the new automatic activity in workflow to use the .NET assembly.
2#
[ProgId("WfHelper")]
[ComVisible(true)]
public class Helper
{
public void SendMail(string workItemId)
{
var session = new Session();
.
.
.
4#
dim helper
set helper = CreateObject("WfHelper")
call helper.SendMail(CurrentWorkItem.ID)
set helper = nothing
FinishActivity “Email has been sent"
ActivityInstance has a WorkItems property (inherited from Activity) that contains a reference to your Component.
OnActivityInstanceFinishPost means that your activity is finished. Therefore there is no more work item associated with it. However, you are getting the process instance and the work item associated with that. If you get null there, then it suggests your workflow process is done and the component has moved out of workflow. From looking at your code, it is quite likely that your ProcessInstance is completed (it won't be null, but it won't have any item associated with it).
I suspect that you've read this post http://www.tridiondeveloper.com/autopublishing-on-workflow-finish suggesting to look in the history. Have you looked into the history via the CM GUI, is the history item there? If it isn't, that's why you get null. A workflow process gets moved to history when it is completed. So double check that you are indeed on the last workflow activity before looking at the history.
By looking at your code, the error seems to be that you are trying to get a history object using activityInstance.ProcessInstance.ID. GetObject() should return an item, but your cast to a ProcessHistory should break and then you quietly eat the exception. You need to pass in the History ID, not the ProcessInstance ID as follows:
ProcessHistory hist = (ProcessHistory)tdse.GetObject(processHistoryId, EnumOpenMode.OpenModeView, Constants.URINULL, filter);
I have a domain object which has a collection of primitive values, which represent the primary keys of another domain object ("Person").
I have a Wicket component that takes IModel<List<Person>>, and allows you to view, remove, and add Persons to the list.
I would like to write a wrapper which implements IModel<List<Person>>, but which is backed by a PropertyModel<List<Long>> from the original domain object.
View-only is easy (Scala syntax for brevity):
class PersonModel(wrappedModel: IModel[List[Long]]) extends LoadableDetachableModel[List[Person]] {
#SpringBean dao: PersonDao =_
def load: List[Person] = {
// Returns a collection of Persons for each id
wrappedModel.getObject().map { id: Long =>
dao.getPerson(id)
}
}
}
But how might I write this to allow for adding and removing from the original List of Longs?
Or is a Model not the best place to do this translation?
Thanks!
You can do something like this:
class PersonModel extends Model<List<Person>> {
private transient List<Person> cache;
private IModel<List<String>> idModel;
public PersonModel( IModel<List<String>> idModel ) {
this.idModel = idModel;
}
public List<Person> getObject() {
if ( cache == null ) {
cache = convertIdsToPersons( idModel.getObject() );
return cache;
}
public void setObject( List<Person> ob ) {
cache = null;
idModel.setObject( convertPersonsToIds( ob ) );
}
}
This isn't very good code but it shows the general idea. One thing you need to consider is how this whole thing will be serialised between requests, you might be better off extending LoadableDetachableModel instead.
Another thing is the cache: it's there to avoid having to convert the list every time getObject() is called within a request. You may or may not need it in practice (depends on a lot of factors, including the speed of the conversion), but if you use it, it means that if something else is modifying the underlying collection, the changes may not be picked up by this model.
I'm not quite sure I understand your question and I don't understand the syntax of Scala.
But, to remove an entity from a list, you can provide a link that simply removes it using your dao. You must be using a repeater to populate your Person list so each repeater entry will have its own Model which can be passed to the deletion link.
Take a look at this Wicket example that uses a link with a repeater to select a contact. You just need to adapt it to delete your Person instead of selecting it.
As for modifying the original list of Longs, you can use the ListView.removeLink() method to get a link component that removes an entry from the backing list.
Does anyone know for an example of GWT's CellTable using RequestFactory and that table is being edited? I would like to list objects in a table (each row is one object and each column is one property), be able to easily add new objects and edit. I know for Google's DynaTableRf example, but that one doesn't edit.
I searched Google and stackoverflow but wasn't able to find one. I got a bit confused with RF's context and than people also mentioned some "driver".
To demonstrate where I currently arrived, I attach code for one column:
// Create name column.
Column<PersonProxy, String> nameColumn = new Column<PersonProxy, String>(
new EditTextCell()) {
#Override
public String getValue(PersonProxy person) {
String ret = person.getName();
return ret != null ? ret : "";
}
};
nameColumn.setFieldUpdater(new FieldUpdater<PersonProxy, String>() {
#Override
public void update(int index, PersonProxy object, String value) {
PersonRequest req = FaceOrgFactory.getInstance().requestFactory().personRequest();
PersonProxy eObject = req.edit(object);
eObject.setName(value);
req.persist().using(eObject).fire();
}
});
and my code for data provider:
AsyncDataProvider<PersonProxy> personDataProvider = new AsyncDataProvider<PersonProxy>() {
#Override
protected void onRangeChanged(HasData<PersonProxy> display) {
final Range range = display.getVisibleRange();
fetch(range.getStart());
}
};
personDataProvider.addDataDisplay(personTable);
...
private void fetch(final int start) {
lastFetch = start;
requestFactory.personRequest().getPeople(start, numRows).fire(new Receiver<List<PersonProxy>>() {
#Override
public void onSuccess(List<PersonProxy> response) {
if (lastFetch != start){
return;
}
int responses = response.size();
if (start >= (personTable.getRowCount()-numRows)){
PersonProxy newP = requestFactory.personRequest().create(PersonProxy.class);
response.add(newP);
responses++;
}
personTable.setRowData(start, response);
personPager.setPageStart(start);
}
});
requestFactory.personRequest().countPersons().fire(new Receiver<Integer>() {
#Override
public void onSuccess(Integer response) {
personTable.setRowCount(response+1, true);
}
});
}
I try to insert last object a new empty object. And when user would fill it, I'd insert new one after it. But the code is not working. I says that user is "attempting" to edit a object previously edited by another RequestContext.
Dilemmas:
* am I creating too many context'es?
* how to properly insert new object into celltable, created on the client side?
* on fieldUpdater when I get an editable object - should I insert it back to table or forget about it?
Thanks for any help.
am I creating too many context'es?
Yes.
You should have one context per HTTP request (per fire()), and a context that is not fire()d is useless (only do that if you/the user change your/his mind and don't want to, e.g., save your/his changes).
You actually have only one context to remove here (see below).
Note that your approach of saving on each field change can lead to "race conditions", because a proxy can be edit()ed by at most one context at a time, and it remains attached to a context until the server responds (and once a context is fired, the proxy is frozen –read-only– also until the server responds).
(this is not true in all cases: when onConstraintViolation is called, the context and its proxies are unfrozen so you can "fix" the constraint violations and fire the context again; this should be safe because validation is done on the server-side before any service method is called).
how to properly insert new object into celltable, created on the client side?
Your code looks OK, except that you should create your proxy in the same context as the one you'll use to persist it.
on fieldUpdater when I get an editable object - should I insert it back to table or forget about it?
I'm not 100% certain but I think you should refresh the table (something like setRowData(index, Collections.singletonList(object)))
BTW, the driver people mention is probably the RequestFactoryEditorDriver from the Editor framework. It won't help you here (quite the contrary actually).