I want to get payload inside dialog participant step in CQ5 under my widget's listener. Below id my dialog.
<?xml version="1.0" encoding="UTF-8" ?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="cq:Dialog" title="Changetemplate" xtype="dialog">
<items jcr:primaryType="cq:WidgetCollection">
<Template jcr:primaryType="cq:Panel">
<items jcr:primaryType="cq:WidgetCollection">
<Path jcr:primaryType="cq:Widget" fieldLabel="Select Template" id="mytemplate" name="./jcr:content/templatepath" xtype="textfield">
<listeners jcr:primaryType="nt:unstructured" afterrender="function(component){ var dialog = CQ.wcm.showTemplate('/content/geometrixx/en'); dialog.show(); }" />
</Path>
</items>
</Template>
</items>
</jcr:root>
Thanks
This can be done with the help of following code in java.
public class MyParticipant implements ParticipantStepChooser {
#Property(value = "An example.")
static final String DESCRIPTION = Constants.SERVICE_DESCRIPTION;
#Property(value = "MyComapany")
static final String VENDOR = Constants.SERVICE_VENDOR;
#Property(value = " Participant Chooser Process")
static final String LABEL=ParticipantStepChooser.SERVICE_PROPERTY_LABEL;
private static final String TYPE_JCR_PATH = "JCR_PATH";
public String getParticipant(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
WorkflowData workflowData = workItem.getWorkflowData();
if (workflowData.getPayloadType().equals(TYPE_JCR_PATH)) {
String path = workflowData.getPayload().toString();
}
return "";
}
}
In ecma script
var workflowData = graniteWorkItem.getWorkflowData();
if (workflowData.getPayloadType() == "JCR_PATH") {
var path = workflowData.getPayload().toString(); }
but if you want to get that path in the dialog specifically try
1. CQ.utils.WCM.getPagePath();
If above solutions doesn't solve your problem then
create a servlet
Hit that servlet from the dialog and get the payload(mostly current path) in that servlet.
refer to this url for reference.
Related
I want to use Data Binding Library & ViewModel
to identify position of clicked item in List.
To know on which view the click happened so that I can trigger different Intent.
Here is my XML file (Currently onclick is on RelativeLayout)
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="orgmembvm"
type="com.support.android.designlibdemo.include.OrgMemb" />
<variable name="orgmembhandlers"
type="com.support.android.designlibdemo.View.MyOrgMembHandlers"/>
</data>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp">
<RelativeLayout
android:id="#+id/org_memb_rec"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="#{orgmembhandlers::onClickOpenEditRec}"
android:padding="8dp">
//Inner Child element
</RelativeLayout>
BindViewHolder of Adaptor
#Override
public void onBindViewHolder(#NonNull OrgMembViewHolder holder, int
position) {
holder.mBinding.setOrgmembvm(orgMembArrayList.get(position));
holder.mBinding.setOrgmembhandlers(new MyOrgMembHandlers());
holder.mBinding.executePendingBindings();
}
Code in Activity Class for getting viewModel attached to Activity.
#Override
protected void onCreate(Bundle savedInstanceState) {
......
......
userModel = ViewModelProviders.of(this).get(OrgMembViewModel.class);
userModel.getAllLive().observe(this, orgMembList -> {
mAdapter.updateorgmemblist(orgMembList);
});
}
How can this be achieved?
1. Take position variable in layout
<variable
name="position"
type="int"/>
2. set position from adapter
#Override
public void onBindViewHolder(#NonNull OrgMembViewHolder holder, int position) {
holder.mBinding.setPosition(position);
}
3. Put int position in onClickOpenEditRec param
public class MyOrgMembHandler {
public void onClickOpenEditRec(int position) {
}
}
4. Pass position from layout
android:onClick="#{()->orgmembhandlers.onClickOpenEditRec(position)}"
Check this answer to see ways of setting click in data binding.
I am new to xamarin.android native. i am learning and developing this app from this tutorial
Tutorial Video link
but i am getting nullreference exception beacuse my actionbar is null.tutorial auther shared source code also.i ahve done same still its not working in my app.
this is my code:
MainMenuPage.axml
<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/fragmentContainer"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</LinearLayout>
MainActivity.cs
[Activity(Label = "HotDogMenuActivityWithTabs",Icon = "#drawable/smallicon",Theme = "#style/AppTheme")]
public class HotDogMenuActivityWithTabs : Activity
{
private ListView hotDogListView;
private List<HotDog> allHotDogs;
private HotDogDataService hotDogDataService;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
AddTab("Favorites", Resource.Drawable.FavoritesIcon, new FavoriteHotDogFragment());
AddTab("Meat Lovers", Resource.Drawable.MeatLoversIcon, new MeatLoversFragment());
AddTab("Veggie Lovers", Resource.Drawable.veggieloversicon, new VeggieLoversFragment());
}
private void AddTab(string tabText, int iconResourceId, Fragment view)
{
var tab = this.ActionBar.NewTab();
tab.SetText(tabText);
tab.SetIcon(iconResourceId);//TODO
tab.TabSelected += delegate (object sender, Android.App.ActionBar.TabEventArgs e)
{
var fragment = this.FragmentManager.FindFragmentById(Resource.Id.fragmentContainer);
if (fragment != null)
e.FragmentTransaction.Remove(fragment);
e.FragmentTransaction.Add(Resource.Id.fragmentContainer, view);
};
tab.TabUnselected += delegate (object sender, Android.App.ActionBar.TabEventArgs e)
{
e.FragmentTransaction.Remove(view);
};
this.ActionBar.AddTab(tab);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (resultCode == Result.Ok && requestCode == 100)
{
var selectedHotDog = hotDogDataService.GetHotDogById(data.GetIntExtra("selectedHotDogId", 0));
var dialog = new Android.App.AlertDialog.Builder(this);
dialog.SetTitle("Confirmation");
dialog.SetMessage(string.Format("You've added {0} time(s) the {1}", data.GetIntExtra("amount", 0), selectedHotDog.Name));
dialog.Show();
}
}
}
Style.xaml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar" >
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
what is wrong i am doing here.please help
tahnkx in advance.
Hope You're all ok.
I have a simple xamarin android application, and trying to integrate facebook share button in it.
I've done all by docs, and other tutorials. App is registered in Facebook.
But the button is showing gray in app, it's disabled.
I don't know what's the problem.
Testing it in Nexus 5, with Android M 6.0.1.
Thanks.
Little update on what I've done so far.
Manifest File
Manifest File
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/ApplicationName" />
<provider android:authorities="com.facebook.app.FacebookContentProvider266540057101076" android:name="com.facebook.FacebookContentProvider" android:exported="true" />
Activity file code snippet
<com.facebook.share.widget.ShareButton
android:id="#+id/fShareButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal" />
And finally controller.
private ShareButton fShareButton;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
getKeyHashes();
FacebookSdk.SdkInitialize(ApplicationContext);
SetContentView(Resource.Layout.details);
fShareButton = FindViewById<ShareButton>(Resource.Id.fShareButton);
fShareButton.Click += FShareButton_Click;
..........
}
private void FShareButton_Click(object sender, EventArgs e)
{
#region Facebook Share Button
View v1 = Window.DecorView.RootView;
v1.DrawingCacheEnabled = true;
Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap(v1.GetDrawingCache(true));
var photoBuilder = new SharePhoto.Builder();
photoBuilder.SetBitmap(bitmap);
var photo = photoBuilder.Build().JavaCast<SharePhoto>();
var photos = new List<SharePhoto>();
photos.Add(photo);
SharePhotoContent photoContent = new SharePhotoContent.Builder().SetPhotos(photos).Build();
fShareButton.ShareContent = photoContent;
#endregion
}
You must set callbackManager and fill ShareContent property in ShareButton, in my example I use ShareLinkContent for the content, but there are other options like "ShareMediaContent", "SharePhotContent", etc., you can get more explanaition about this in https://developers.facebook.com/docs/sharing/android/?locale=en_US :
fShareButton = FindViewById<ShareButton>(Resource.Id.fShareButton);
callbackManager = CallbackManagerFactory.Create();
fShareButton.RegisterCallback(callbackManager, this);
var content = new ShareLinkContent.Builder();
content.SetContentUrl(Android.Net.Uri.Parse("https://www.mivinco.com/linkapp_an9.html"));
var hashtag = new ShareHashtag.Builder();
hashtag.SetHashtag("#porqueTuExperienciaCuenta");
content.SetShareHashtag((ShareHashtag)hashtag.Build());
fShareButton.ShareContent = content.Build();
Also, you should implement IFacebookCallback interface in your activity:
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
}
It works fine in my Android app. Let me know if it works fine in your app too.
I have 2 layouts,in first layout I have EditText,Button and in second layout I have TextView. What I want is when i write something in EditText to copy that in second layout when you press button,but i get crash every time. Is there any way to use components from two layouts or i am missing something. If this is imposible another way would be good. Thx
main activity
public void onCreate(Bundle ivansad) {
super.onCreate(ivansad);
setContentView(R.layout.activity_main);
Button Start = (Button) findViewById(R.id.bStart);
Start.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
setContentView(R.layout.numbers);
Intent Changeto2 = new Intent (MainAct.this, Numgen.class);
startActivity(Changeto2);
}
});
}
second activity
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.numbers);
Button Next = (Button)findViewById(R.id.bNext);
final EditText text = (EditText)findViewById(R.id.broj1);
final TextView edit = (TextView)findViewById(R.id.lb1);
Next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
edit.setText(text.getText());
}
});
}
First layout
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="Deprecated"
android:background="#drawable/grey_bg" >
<Button
android:id="#+id/bNext"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_x="-1dp"
android:layout_y="405dp"
android:background="#000000"
android:text="Dalje"
android:textColor="#ffffff"
tools:ignore="HardcodedText" />
<EditText
android:textColor="#ffffff"
android:id="#+id/broj1"
android:layout_width="154dp"
android:layout_height="50dp"
android:layout_x="164dp"
android:layout_y="6dp"
android:background="#drawable/text_bg"
android:ems="10"
android:gravity="center"
android:hint="1-49"
android:inputType="number"
tools:ignore="HardcodedText" >
</AbsoluteLayout>
Second Layout
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/grey_bg"
android:orientation="vertical">
<TextView
android:id="#+id/lb1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_x="80dp"
android:layout_y="107dp"
android:gravity="center"
android:text=" "
android:textSize="18sp"
tools:ignore="HardcodedText" />
</AbsoluteLayout>
What you want to do is have two separate activities, one to edit the text, and one to display it.
The first one you want to set the layout to layout_main, and set a callback for the button. Inside the callback you want:
final EditText text = (EditText)findViewById(R.id.broj1);
Intent intent = new Intent(MainAct.this, NumGen.class);
Bundle bundle = new Bundle();
bundle.putString("mString",text.getText().toString());
intent.putExtras(bundle);
startActivity(intent);
Then inside your second activity (NumGen?) you can get that string you saved by doing this:
Bundle data = getIntent().getExtras();
String mString="";
if(data.containsKey("mString")){ mString=data.getString("mString"); }
One of the main issues it looks like you might be having is the ids defined in your XML files aren't the same as the ids in your code. After that, read up on how Activities work and pass information.
I got a simple form validation and submission that works great
Here is my struts.xml :
<action name="register" class="registerAction">
<interceptor-ref name="defaultWithoutAuthenticationStack"/>
<result type="tiles" name="input">
<param name="titleKey">global.title.register</param>
<param name="location">register</param>
</result>
<result type="tiles" name="success">register.success</result>
</action>
My jsp form :
<s:form method="post" action="register.action" validate="true">
<s:textfield name="usernameRegister" id="usernameRegister" key="global.username" labelposition="left" />
<s:password name="passwordRegister" id="passwordRegister" key="global.password" labelposition="left" />
<s:password name="passwordConfirmRegister" id="passwordConfirmRegister" key="global.password.confirm" labelposition="left" />
<s:textfield name="emailRegister" id="emailRegister" key="global.email" labelposition="left" />
<s:submit key="global.register" name="submitRegister" method="goRegister"></s:submit>
</s:form>
And my submit function :
public String goRegister(){
user.setUsername(getUsernameRegister());
user.setPassword(getPasswordRegister());
user.setEmail(getEmailRegister());
userService.addUser(user);
ArrayList<String> successMessageUsername = new ArrayList<String>();
successMessageUsername.add(getUsernameRegister());
this.addActionSuccess(getText("global.register.success", successMessageUsername));
return SUCCESS;
}
Nothing fancy !
The problem is I got a windows asking for resubmit form informations when I refresh my page on success page or form page (when validation failed)
How can I prevent that ?
Thx
EDIT : I add the action messages and fields messages preservation to my question
How to preserve the actions messages and fields messages (validation) with a redirection ?
Use the post-redirect-get pattern.
On success, redirect to the "you've registered" page. That way if the user refreshes, they just get that same page again.
Oki after Dave Newton's suggestion I dig up a little to complete the correct way to do so :)
Here is my answer so far, no more refresh, backward or forward resubmission of your form and preserve the ValidationAware messages (errors and messages)
My struts.xml :
<action name="register" class="registerAction">
<interceptor-ref name="defaultWithoutAuthenticationStack"/>
<result type="tiles" name="input">
<param name="titleKey">global.title.register</param>
<param name="location">register</param>
</result>
<result name="success" type="redirectAction">index</result>
</action>
<action name="goRegister" class="registerAction">
<interceptor-ref name="defaultWithoutAuthenticationStack"/>
<result name="input" type="redirectAction">register</result>
<result name="success" type="redirectAction">index</result>
</action>
And my jsp :
<s:form method="post" action="goRegister" validate="true">
<s:textfield name="usernameRegister" id="usernameRegister" key="global.username" labelposition="left" />
<s:password name="passwordRegister" id="passwordRegister" key="global.password" labelposition="left" />
<s:password name="passwordConfirmRegister" id="passwordConfirmRegister" key="global.password.confirm" labelposition="left" />
<s:textfield name="emailRegister" id="emailRegister" key="global.email" labelposition="left" />
<s:submit key="global.register" name="submitRegister" method="goRegister"></s:submit>
</s:form>
I found the answer to messages preservation here, the guy store the differents action messages (messages, errors, fields error) in session when we are in a redirect situation and push them to the action messages otherwise
Here is my implementation (you will find I add success messages to the default messages and errors messages) :
public class MessagesInterceptor extends AbstractInterceptor {
/**
*
*/
private static final long serialVersionUID = -6230422534075664728L;
private Map<String, Object> session;
#Override
public String intercept(ActionInvocation invocation) throws Exception {
session = invocation.getInvocationContext().getSession();
MyAction action = (MyAction) invocation.getAction();
this.addSessionMessagesInActionMessages(action);
String output = invocation.invoke();
Result result = invocation.getResult();
// If it's a redirection, store the messages in session
if(result instanceof ServletRedirectResult || result instanceof ServletActionRedirectResult)
this.addActionMessagesInSessionMessages(action);
return output;
}
#SuppressWarnings("unchecked")
private void addSessionMessagesInActionMessages(MyAction action) {
Object messagesObject = getSession().remove(SESSION_ACTION_MESSAGES);
if (messagesObject != null) {
List<String> sessionMessages = (List<String>)messagesObject;
for (String sessionMessage : sessionMessages) {
action.addActionMessage(sessionMessage);
}
}
Object errorsObject = getSession().remove(SESSION_ACTION_ERRORS);
if (errorsObject != null) {
List<String> sessionErrors = (List<String>)errorsObject;
for (String sessionError : sessionErrors) {
action.addActionError(sessionError);
}
}
Object successObject = getSession().remove(SESSION_ACTION_SUCCESS);
if (successObject != null) {
List<String> sessionSuccessList = (List<String>)successObject;
for (String sessionSuccess : sessionSuccessList) {
action.addActionSuccess(sessionSuccess);
}
}
#SuppressWarnings("rawtypes")
Map<String, List<String>> fieldErrors = (Map) session.remove(SESSION_FIELD_ERRORS);
if (fieldErrors != null && fieldErrors.size() > 0){
for (Map.Entry<String, List<String>> fieldError : fieldErrors.entrySet()){
for (String message : fieldError.getValue()){
action.addFieldError(fieldError.getKey(), message);
}
}
}
}
protected void addActionMessagesInSessionMessages(MyAction action) throws Exception{
Collection<String> actionErrors = action.getActionErrors();
if (actionErrors != null && actionErrors.size() > 0){
session.put(SESSION_ACTION_ERRORS, actionErrors);
}
Collection<String> actionMessages = action.getActionMessages();
if (actionMessages != null && actionMessages.size() > 0){
session.put(SESSION_ACTION_MESSAGES, actionMessages);
}
Collection<String> actionSuccess = action.getActionSuccess();
if (actionSuccess != null && actionSuccess.size() > 0){
session.put(SESSION_ACTION_SUCCESS, actionSuccess);
}
Map<String, List<String>> fieldErrors = action.getFieldErrors();
if (fieldErrors != null && fieldErrors.size() > 0){
session.put(SESSION_FIELD_ERRORS, fieldErrors);
}
}
public Map<String, Object> getSession() {
return session;
}
public void setSession(Map<String, Object> session) {
this.session = session;
}
}
MyAction inherits ActionSupport
Hope this will help someone ;)
Action mesages and field validation message are now preserved with no refresh problem
But my fields values are now blank, how do I retrieve / store them to repopulate my fields ?